﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

using log4net;
using AutoFacUtils;
using CashFlow.Db.DAL;

namespace SysTool
{
    static class Program
    {
        private static ILog _logger = LogManager.GetLogger(typeof(Program));

        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            _logger.Info("SysTool Startup...");

            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            Application.ThreadException += Application_ThreadException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            SqlSugarHelper.Init();
            AutoFacHelper.Init(new string[] {
                "CashFlow.Db.IRepository",
                "CashFlow.Db.Repository",
                "CashFlow.Web.IService",
                "CashFlow.Web.Service"});

            Application.Run(new Form1());
        }

        private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            _logger.Fatal(e.Exception);
            MessageBox.Show("SysTool遇到未知异常，程序即将退出！");
            Application.Exit();
        }

        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Exception ex = e.ExceptionObject as Exception;
            _logger.Fatal(ex);
            MessageBox.Show("SysTool遇到未知异常，程序即将退出！");
            Application.Exit();
        }
    }
}
